package only.level5.railgun.ysartifactsimulation.artifact;

import java.util.concurrent.ThreadLocalRandom;

public enum SubElement {
    flatAtk(1,14,16,18,19),
    flatHp(2,209,239,269,299),
    flatDef(3,16,19,21,23),
    percentAtk(4,0.041,0.047,0.053,0.058),
    percentHp(5,0.041,0.047,0.053,0.058),
    percentDef(6,0.051,0.058,0.066,0.073),
    elementalMastery(7,16,19,21,23),
    energyRecharge(8,0.045,0.052,0.058,0.065),
    critRate(9,0.027,0.031,0.035,0.039),
    critDamage(10,0.054,0.062,0.07,0.078);

    int code;
    double v1;
    double v2;
    double v3;
    double v4;

    ArtifactScoreFunction artifactScoreFunction;

    SubElement(int i, double v1, double v2, double v3, double v4) {
        this.code = i;
        this.v1 = v1;
        this.v2 = v2;
        this.v3 = v3;
        this.v4 = v4;
    }
    public static SubElement getInstanceByCode(int code){
        return switch (code) {
            case 1 -> flatAtk;
            case 2 -> flatHp;
            case 3 -> flatDef;
            case 4 -> percentAtk;
            case 5 -> percentHp;
            case 6 -> percentDef;
            case 7 -> elementalMastery;
            case 8 -> energyRecharge;
            case 9 -> critRate;
            case 10 -> critDamage;
            default -> null;
        };
    }

    public double finalValue(int times){
        double value = 0d;
        for (int i = 0; i < times; i++) {
            ThreadLocalRandom random = ThreadLocalRandom.current();
            int rValue = random.nextInt(4);
            if(rValue == 0){
                value += this.v1;
            }else if(rValue == 1){
                value += this.v2;
            }else if(rValue == 2){
                value += this.v3;
            }else {
                value += this.v4;
            }
        }
        return value;
    }
}
